/***************************************************************************
 * *   File name: TaskDispatcher.cpp
 * *    Describe: 业务处理分发类
 * *  Created on: 2016-8-6
 * *      Author: dengxiudong
 * *************************************************************************/


#include "TaskDispatcher.h"
#include "Protocol.h"
#include <deque>
#include <memory>

TaskDispatcher* TaskDispatcher::m_instance;
TaskDispatcher::TaskDispatcher()
{   
}

TaskDispatcher::~TaskDispatcher()
{  
}

TaskDispatcher* TaskDispatcher::getInstance()
{
    if (m_instance==nullptr)
    {
        m_instance = new TaskDispatcher;
    }
    return m_instance;
}

void TaskDispatcher::addTask(std::shared_ptr<Msg> msg)
{
	std::unique_lock<std::mutex> locker(m_mtx);
    m_taskQue.push_back(msg);
	m_cond.notify_one();
}

void TaskDispatcher::getTask(std::deque<std::shared_ptr<Msg>> &taskQue)
{
	std::unique_lock<std::mutex> locker(m_mtx);
	while (m_taskQue.empty())
	{
		m_cond.wait(locker);
	}
    m_taskQue.swap(taskQue);
}




